package net.xiduth.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;

import net.xiduth.game.player.Player;

public class ChangePassword extends Thread {

/*	Player c;
	Connections con;
	String username, password;

	@Override
	public void run() {
		try {
			this.con.createConnection();

			ResultSet rs = con.query("select * from `users` where `username`= '"+username+"'");
			
			if(rs.next()) {
				
				con.query("update `users` set `password`='"+md5(password)+"' where `username`='"+username+"'");
				System.out.println("password changed for "+ username);
				this.con.destroyConnection();
			} else {
				
				System.out.println("Error changing password!");
				this.con.destroyConnection();
				return;
				
			}
	
		} catch (final Exception e) {
			e.printStackTrace();
		}
	}

	public ChangePassword(String username, String password) {
		this.con = new Connections("donate");
		this.username = username;
		this.password = password;
	}
	public String md5(String plaintext) {
		MessageDigest m;
		try {
			m = MessageDigest.getInstance("MD5");
			m.reset();
			m.update(plaintext.getBytes());
			byte[] digest = m.digest();
			BigInteger bigInt = new BigInteger(1,digest);
			String hashtext = bigInt.toString(16);
			// Now we need to zero pad it if you actually want the full 32 chars.
			while(hashtext.length() < 32 ){
			  hashtext = "0"+hashtext;
			}
			return hashtext.toString();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}*/
}
